package fdoj.eventInvitations.servlet;

import java.io.IOException;

import javax.ejb.EJB;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import fdoj.eventInvitations.dao.PersonDao;
import fdoj.eventInvitations.dao.PersonDaoBean;
import fdoj.eventInvitations.entity.Person;


public class LogoutController extends HttpServlet{
	@EJB
	private PersonDao personDao;
	
	
	@Override
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		try{
			HttpSession session = request.getSession(true);
			
			if(session.getAttribute("loggedUser")!=null){
				session.removeAttribute("loggedUser");
			}
			else{
				response.sendRedirect(response.encodeRedirectURL("./index"));
				return;
			}
			
		    response.sendRedirect(response.encodeRedirectURL("./index"));
			
		}catch (Exception e) {
			e.printStackTrace();
		}
	}
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		doGet(req, resp);
	}

}
